﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mozlite.Components
{
    /// <summary>
    /// 用户查询。
    /// </summary>
    public class UserQuery : BaseQuery
    {
        /// <summary>
        /// 附加条件。
        /// </summary>
        /// <returns>获取附加条件。</returns>
        protected override string AppendWheres()
        {
            if(RoleLevel == null || RoleLevel.Value > Self.RoleLevel)
                return "RoleLevel < @RoleLevel";
            return "RoleLevel = @RoleLevel";
        }

        /// <summary>
        /// 用户等级。
        /// </summary>
        public RoleLevel? RoleLevel { get; set; }

        /// <summary>
        /// 获取参数匿名类型。
        /// </summary>
        /// <returns>返回参数匿名类型。</returns>
        protected override object AppendParameters()
        {
            if(RoleLevel == null || RoleLevel.Value > Self.RoleLevel)
                return new { RoleLevel = Self.RoleLevel };
            return new { RoleLevel = RoleLevel.Value };
        }

        /// <summary>
        /// 获取分页列表。
        /// </summary>
        /// <typeparam name="T">实例类型。</typeparam>
        /// <param name="size">返回总记录数。</param>
        /// <returns>返回实例列表。</returns>
        public override List<T> Load<T>(out int size)
        {
            return Fetch<T>("moz_Users", out size);
        }
        /// <summary>
        /// 获取用户列表。
        /// </summary>
        /// <param name="size">返回中记录数。</param>
        /// <returns>返回用户列表。</returns>
        public List<User> Load(out int size)
        {
            return Load<User>(out size);
        }
    }
}
